#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int P=810;
const int INF=0x3f3f3f3f;
int n,p,c;
int arr[P];
int vis[P];
int dp[P];
vector<pair<int,int>> edge[P];
struct cmp{
	bool operator()(pair<int,int>& p1,pair<int,int>& p2)
	{
		if(p1.second==p2.second)
			return p1.first>p2.first;
		return p1.second>p2.second;
	}
};
int dijkstra(int x)
{
	
	for(int i=0;i<=p;i++)
	{
		dp[i]=INF;
		vis[i]=0;
	}
	dp[x]=0;
	priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> q;
	q.push({x,0});
	while(q.size())
	{
		int r=q.top().first;
		vis[r]=1;
		q.pop();
		for(auto& e:edge[r])
		{
			if(vis[e.first])
				continue;
// 			vis[e.first]=1;
			if(dp[e.first]>dp[r]+e.second)
			{
				dp[e.first]=dp[r]+e.second;
				q.push({e.first,dp[e.first]});
			}
		}
	}
	int ret=0;
	for(int i=1;i<=p;i++)
	{
	    if(dp[i]==INF && arr[i])
	        return INF;
		ret+=arr[i]*dp[i];
	}
	return ret;
}
int main()
{
	cin>>n>>p>>c;
	for(int i=0;i<n;i++)
	{
		int t;
		cin>>t;
		arr[t]++;
	}
	
	for(int i=0;i<c;i++)
	{
		int a,b,d;
		cin>>a>>b>>d;
		edge[a].push_back({b,d});
		edge[b].push_back({a,d});
	}
	int ret=INF;
	for(int i=1;i<=p;i++)
	{
		memset(vis,0,sizeof(vis));
		int t=dijkstra(i);
		ret=min(t,ret);
	}
	
	cout<<ret<<endl;
	
	return 0;
}
